package com.itheima.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.SmsCouponProductRelationMapper;
import com.itheima.pojo.SmsCouponProductCategoryRelation;
import com.itheima.pojo.SmsCouponProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author lenovo
 * @description 针对表【sms_coupon_product_relation(优惠券和产品的关系表)】的数据库操作Service实现
 * @createDate 2022-10-11 14:26:17
 */
@DubboService
public class SmsCouponProductRelationApiImpl implements SmsCouponProductRelationApi {
    @Autowired
    private SmsCouponProductRelationMapper couponProductRelationMapper;

    //保存couponProductRelation
    @Override
    public void saveCouponProductRelation(SmsCouponProductRelation couponProductRelation) {
        couponProductRelationMapper.insert(couponProductRelation);
    }

    //根据couponId删除couponProductRelation
    @Override
    public void deleteByCouponId(Integer id) {
        LambdaQueryWrapper<SmsCouponProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(id), SmsCouponProductRelation::getCouponId, id);
        couponProductRelationMapper.delete(lqw);
    }

    //更新SmsCouponProductRelation对象
    @Override
    public void updateCouponProductRelation(SmsCouponProductRelation couponProductRelation) {
        couponProductRelationMapper.updateById(couponProductRelation);
    }

    //查找SmsCouponProductRelation
    @Override
    public SmsCouponProductRelation findByCouponId(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(couponId), SmsCouponProductRelation::getCouponId, couponId);
        return couponProductRelationMapper.selectOne(lqw);
    }
}




